package entityJPA;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * The persistent class for the user database table.
 * 
 */
@Entity
@Table(name = "user")
@NamedQueries({
		@NamedQuery(name = "User.findAll", query = "SELECT u FROM User u"),
		@NamedQuery(name = "User.findByUsername", query = "SELECT u FROM User u WHERE u.username LIKE :us"),
		@NamedQuery(name = "User.filterByFirstName", query = "SELECT u FROM User u WHERE u.firstName LIKE :fn"),
		@NamedQuery(name = "User.filterByLastName", query = "SELECT u FROM User u WHERE u.lastName LIKE :ln"),
		@NamedQuery(name = "User.findAllActive", query = "SELECT u FROM User u WHERE u.isAlive = TRUE")})
public class User implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(unique = true, nullable = false)
	private int idUser;

	@Column(nullable = false, length = 15)
	private String cellNumber;

	@Column(length = 45)
	private String description;

	@Column(nullable = false, length = 45)
	private String email;

	@Column(nullable = false, length = 45)
	private String firstName;

	@Column(length = 15)
	private String homeNumber;

	@Column(nullable = false)
	private boolean isAlive;

	@Column(nullable = false, length = 45)
	private String lastName;

	@Column(nullable = false, length = 45)
	private String password;

	@Column(length = 45)
	private String rank;

	@Column(nullable = false, length = 45, unique = true)
	private String username;

	// uni-directional many-to-one association to Usertype
	@ManyToOne
	@JoinColumn(name = "idUserType")
	private Usertype usertype;

	public User() {

	}

	public User(int idUser, String password, String firstName, String lastName,
			String homeNumber, String cellNumber, String email, String rank,
			String description, Usertype usertype, boolean isAlive) {
		this.idUser = idUser;
		this.cellNumber = cellNumber;
		this.description = description;
		this.email = email;
		this.firstName = firstName;
		this.lastName = lastName;
		this.homeNumber = homeNumber;
		this.isAlive = isAlive;
		this.rank = rank;
		this.password = password;
		this.usertype = usertype;
	}

	public int getIdUser() {
		return this.idUser;
	}

	public void setIdUser(int idUser) {
		this.idUser = idUser;
	}

	public String getCellNumber() {
		return this.cellNumber;
	}

	public void setCellNumber(String cellNumber) {
		this.cellNumber = cellNumber;
	}

	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getEmail() {
		return this.email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getFirstName() {
		return this.firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getHomeNumber() {
		return this.homeNumber;
	}

	public void setHomeNumber(String homeNumber) {
		this.homeNumber = homeNumber;
	}

	public boolean getIsAlive() {
		return this.isAlive;
	}

	public void setIsAlive(boolean isAlive) {
		this.isAlive = isAlive;
	}

	public String getLastName() {
		return this.lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getRank() {
		return this.rank;
	}

	public void setRank(String rank) {
		this.rank = rank;
	}

	public String getUsername() {
		return this.username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public Usertype getUsertype() {
		return this.usertype;
	}

	public void setUsertype(Usertype usertype) {
		this.usertype = usertype;
	}

	public String toString() {
		return username + " " + firstName + " " + lastName;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + idUser;
		result = prime * result
				+ ((username == null) ? 0 : username.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		User other = (User) obj;
		if (idUser != other.idUser)
			return false;
		if (username == null) {
			if (other.username != null)
				return false;
		} else if (!username.equals(other.username))
			return false;
		return true;
	}


}